package org.inspursc.s0517.health.evaluation.service.impl;
import org.inspursc.s0517.health.evaluation.converter.InsAnRadioConverter;
import org.inspursc.s0517.health.evaluation.dao.InsAnRadioDao;
import org.inspursc.s0517.health.evaluation.dto.InsAnRadioDTO;
import org.inspursc.s0517.health.evaluation.entity.InsAnRadio;
import org.inspursc.s0517.health.evaluation.service.InsAnRadioService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author B_Dream
 * @date 2018/6/6 17:06
 */
@Service
public class InsAnRadioServiceImpl implements InsAnRadioService {

    @Autowired
    InsAnRadioDao insAnRadioDao;

    @Override
    public InsAnRadio saveAnRadio(InsAnRadio insanRadio) {
        return insAnRadioDao.save(insanRadio);

    }

    @Override
    public List<InsAnRadio> saveBatchAnRadio(List<InsAnRadio> insAnRadios) {
        return insAnRadioDao.saveAll(insAnRadios);

    }

    @Override
    public List<InsAnRadioDTO> findAnRadio(Integer suId, Integer organizationId) {
        List<InsAnRadio> anRadios = insAnRadioDao.findAllBySurveyIdAndOrganizationId(suId,organizationId);

        List<InsAnRadioDTO> anRadioDTOS = anRadios.stream().map(InsAnRadioConverter::converter).collect(Collectors.toList());
        return anRadioDTOS;
    }

    @Override
    public List<InsAnRadioDTO> findAllBySuAnswerId(Integer suAnswerId) {
        List<InsAnRadio> insAnRadios = insAnRadioDao.findAllByAssessmentResultId(suAnswerId);
        List<InsAnRadioDTO> insAnRadioDTOS = insAnRadios.stream().map(InsAnRadioConverter::converter).collect(Collectors.toList());
        return insAnRadioDTOS;
    }

    @Override
    public int deleteByAssessmentResultId(Integer assessmentResultId){
       return insAnRadioDao.deleteByAssessmentResultId(assessmentResultId);
    }
}
